
package com.kweative.lingua.demo.controller;
import com.kweative.cluster.Cluster;
import com.kweative.lingua.demo.Demo;
import com.kweative.lingua.demo.model.ChatMessage;
import com.kweative.lingua.demo.model.UserModel;
import com.kweative.lingua.server.Controller;
import com.kweative.lingua.server.annotations.MethodInfo;
import java.util.Date;
import java.util.LinkedList;

/**
 *
 * @author henrik
 */
public class Chat extends Controller<Demo> {
    
    @MethodInfo(parms={"user","message"})
    public boolean send(String username,String message) {
        if (!getApp().users().containsKey(username)) {
            return false;
        }
        UserModel user = getApp().users().get(username);

        getApp().messages().addFirst(new ChatMessage(user,message,new Date()));

        Cluster.store("messages",getApp().messages());

        return true;
    }
    
    public LinkedList<ChatMessage> list() {
        return getApp().messages();
    }
}
